package com.bsoft.exchange.service;



import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bsoft.exchange.dao.his.WholeQueuesMapper;
import com.bsoft.exchange.domain.Queues;
import com.bsoft.exchange.domain.WholeQueues;

@Service
public class WholeQueuesService {
	
	@Autowired
	WholeQueuesMapper wholeQueuesmapper;
	
	public List<WholeQueues> selectList(String hospitalCode,int pageNo,int pageSize,String query) {
		List<Map<String,Object>> wholeQueues = wholeQueuesmapper.selectList(hospitalCode,pageNo,pageSize,query);
		Map<String, WholeQueues> map = new HashMap<String,WholeQueues>();
		for (Map<String, Object> wholeQueue : wholeQueues) {
			if(!map.containsKey(wholeQueue.get("departmentName").toString())){
				WholeQueues item = new WholeQueues();
				item.setDepartmentName((String)wholeQueue.get("departmentName"));
				item.setAdmitAddress((String)wholeQueue.get("admitAddress"));
				item.setListQueues(new ArrayList());
				map.put(wholeQueue.get("departmentName").toString(), item);
			}
			WholeQueues wholeQueu = map.get((String)wholeQueue.get("departmentName"));
			Queues queues = new Queues();
			queues.setCurrentNumber(String.valueOf(wholeQueue.get("currentNumber")));
			queues.setQueueName((String)wholeQueue.get("queueName"));
			queues.setDoctorType((Integer)(wholeQueue.get("doctorType")));
			queues.setWaitingNumber((Integer)(wholeQueue.get("waitingNumber")));
			queues.setRemainNumber((Integer)(wholeQueue.get("remainNumber")));
			wholeQueu.getListQueues().add(queues);
		}
		 List<WholeQueues> list =  new  ArrayList();
			for (Entry<String, WholeQueues> entry : map.entrySet()) {
				list.add(entry.getValue());
			}
		return list;
	}
	

}
